/**
 * Copyright (c) 2012 Nokia Corporation.
 */

import QtQuick 1.1

Item {
    id: splashScreen

    property string text: ""
    signal textChangeComplete()
    signal hidden()

    /*!
      Hides this splash screen using a transition. hidden() signal is emitted
      when the transition is complete.
    */
    function hide()
    {
        console.debug("SplashScreen.qml: hide()");
        hideAnimation.start();
    }

    // Background image and overlaying gradient
    Image {
        anchors.centerIn: parent
        width: parent.width > parent.height ? parent.height : parent.width;
        height: parent.width > parent.height ? parent.width : parent.height;
        rotation: parent.width > parent.height ? -90 : 0;
        source: "qrc:/splash-screen-bg.png"
    }
    Rectangle {
        anchors.fill: parent
        gradient: Gradient {
            GradientStop { position: 0.0; color: "#ccbbccff" }
            GradientStop { position: 1.0; color: "#ccffffff" }
        }
    }

    // Application title label
    Text {
        anchors {
            left: parent.left
            right: parent.right
            verticalCenter: parent.verticalCenter
            margins: 20
        }

        color: "#404040"
        font.pixelSize: 80
        wrapMode: Text.WordWrap
        text: "Places Around"
    }

    // Text for showing the current status, e.g. "Loading..."
    Text {
        id: statusText

        anchors {
            bottom: parent.bottom
            margins: 10
        }

        color: "#404040"
        font.pixelSize: 28
    }

    onTextChanged: {
        console.debug("Changing status text to: \"" + text + "\"");
        textChangeAnimation.restart();
    }

    // Animation that is performed when the status text is changed
    SequentialAnimation {
        id: textChangeAnimation

        // Move the existing text and make the text invisible
        ParallelAnimation {
            NumberAnimation {
                target: statusText
                property: "x"
                to: 200
                easing.type: Easing.InOutQuad
                duration: statusText.text.length ? 500 : 1;
            }
            NumberAnimation {
                target: statusText
                property: "opacity"
                to: 0
                duration: statusText.text.length ? 500 : 1;
            }
        }

        // Change the text and make it appear from the left
        ScriptAction {
            script: {
                statusText.text = splashScreen.text;
                statusText.x = -180
            }
        }

        // Make the new text to enter from the left and make the text visible
        ParallelAnimation {
            NumberAnimation {
                target: statusText
                property: "x"
                to: 10
                easing.type: Easing.InOutQuad
                duration: 500
            }
            NumberAnimation {
                target: statusText
                property: "opacity"
                to: 1
                duration: 500
            }
        }

        ScriptAction { script: splashScreen.textChangeComplete(); }
    }

    // Animation for hiding this splash screen
    SequentialAnimation {
        id: hideAnimation

        PauseAnimation { duration: 200 }
        NumberAnimation {
            target: splashScreen
            property: "opacity"
            to: 0.0
            duration: 500
        }
        ScriptAction { script: splashScreen.hidden(); }
    }
}

// End of file.
